//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.restaurant.application.shop;

import com.google.common.base.Strings;
import com.nebutown.base.ViewSpec;
import com.nebutown.base.data.View;
import com.nebutown.base.data.ViewUpdate;
import com.nebutown.commonunits.dataface.DataModes;
import com.nebutown.commonunits.dataface.FormShell;
import com.nebutown.commonunits.dataface.definitions.PageForm;
import com.nebutown.commonunits.uidataface.UIDataFace;
import com.nebutown.commonunits.utils.DateTimeUtils;
import com.nebutown.generation.basicdata.StringMap;
import com.restaurant.application.shop.support.AbstractShop;
import com.restaurant.application.shop.support.ShopData;
import com.restaurant.application.shoplist.ShopList;
import java.util.List;
import java.util.Objects;

public class ShopImpl extends AbstractShop {
    public ShopImpl() {
    }

    public ViewUpdate save(ShopData save, int[] seq) {
        if (Strings.isNullOrEmpty(save.getName())) {
            return this.returnViewCall(this.buildViewCall(this.unitPosition(), "showErrorMessage", (List)null, (new StringMap()).putData("errorMessage", "请填写门店名称！")));
        } else {
            if (save.getSupport2d() == null) {
                save.setSupport2d(false);
            }

            if (save.getSupport2d() && Strings.isNullOrEmpty(save.getEntityId())) {
                return this.returnViewCall(this.buildViewCall(this.unitPosition(), "showErrorMessage", (List)null, (new StringMap()).putData("errorMessage", "请填写门店二维火编号！")));
            } else {
                if (Objects.nonNull(this.getData().getCreateTime())) {
                    save.withCreateTime(this.getData().getCreateTime());
                } else {
                    save.withCreateTime(DateTimeUtils.getCurrentMillisecond());
                    ((ShopList)this.getSingleton(ShopList.class)).addShop(this.getId());
                }

                save.withModifyTime(DateTimeUtils.getCurrentMillisecond());
                this.setData(save);
                return this.returnPopFromContainer(this.getId(), false);
            }
        }
    }

    public ViewUpdate cancel(int[] seq) {
        return this.returnPopFromContainer(this.getId(), false);
    }

    public View getFullView() {
        return this.getView(this.getData(), DataModes.EDIT);
    }

    private View getView(ShopData data, DataModes modes) {
        PageForm pageForm = this.newFormShell(data.duplicate(), modes).getForm();
        return ((UIDataFace)this.getSingleton(UIDataFace.class)).newUniForm(this.unitPosition(), pageForm);
    }

    public View getViewLead(ViewSpec viewSpec) {
        return null;
    }

    public ShopData findData() {
        return this.getData().duplicate();
    }

    private FormShell newFormShell(ShopData shopData, DataModes modes) {
        FormShell formShell = new FormShell("店铺", 3, 5);
        formShell.source(shopData, DataModes.EDIT);
        formShell.at(0, 0, "店铺名称").stringField("name", shopData.getName()).placeHolder("名称").notNull().setEditable(true);
        formShell.at(0, 1, "店铺编号").stringField("id", shopData.getId()).placeHolder("门店编号").notNull().setEditable(true);
        formShell.at(1, 0, "联系电话").stringField("phone", shopData.getPhone()).placeHolder("联系电话").lengthLimit(11).setEditable(true);
        formShell.at(1, 1, "邮箱").stringField("mail", shopData.getMail()).placeHolder("邮箱").setEditable(true);
        formShell.at(2, 0, "支持二维火").checkentryField("support2d", shopData.getSupport2d()).setEditable(true);
        formShell.at(3, 0, "门店二维火编号").stringField("entityId", shopData.getEntityId()).setEditable(true);
        formShell.at(4, 0, "地址").large(3, 1).addressEntryField("address", shopData.getAddress()).placeHolder("地址").setEditable(true);
        formShell.at(5, 0, "图片").styles("", "height:200px").imageentryField("imgUrl", shopData.getImgUrl()).placeHolder("图片").setEditable(true);
        if (!Strings.isNullOrEmpty(this.getPath(CMD_SAVE, new int[0]))) {
            formShell.at(6, 0, (String)null).buttonField(this.getPath(CMD_SAVE, new int[0]), "保存", (String)null, true);
        }

        formShell.at(6, 1, (String)null).buttonField(this.getPath(CMD_CANCEL, new int[0]), "取消", (String)null, false);
        return formShell;
    }
}
